package com.botao.tip.convert;

import com.botao.tip.entity.Department;
import com.botao.tip.entity.User;
import com.botao.tip.utils.DateUtil;
import com.botao.tip.utils.RoleUtil;
import com.botao.tip.vo.UserVo;


public class UserConvert {
    public static UserVo convertToUserVo(User user) {
        Department department = new Department();
        UserVo userVo = new UserVo();
        userVo.setId(user.getId());
        userVo.setUsername(user.getUsername());
        userVo.setTrueName(user.getTrueName());
        userVo.setGender(user.getGender() == 0 ? "男" : "女");
        if (user.getBirthday() != null) {
            userVo.setBirthday(DateUtil.formatYear(user.getBirthday()));
        }
        userVo.setAddress(user.getAddress());
        userVo.setRoleId(user.getRole());
        userVo.setRole(RoleUtil.getRole(user.getRole()));
        userVo.setStatus(user.getStatus());
        userVo.setCreated(DateUtil.formatYear(user.getCreated()));
        userVo.setDepartmentId(user.getDepartmentId());
        userVo.setDepartment(department.getDepartment());
        return userVo;
    }
}
